home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / TEST.ZIP / TESTLIST.ASM < prev    next >
Assembly Source File  |  1992-03-13  |  6KB  |  365 lines

  1.         include     stdlib.a
  2.         includelib    stdlib.lib
  3.         include        lists.a
  4.  
  5. NodeSize    equ    (size Node)
  6. NodeTyp        struc
  7.         db    NodeSize dup (0)
  8. NodeString    db    "     "
  9.         db    0
  10. NodeTyp        ends
  11.  
  12.  
  13. dseg        segment    para public 'data'
  14.  
  15. MyList        list    <(size NodeTyp) - NodeSize>
  16. Node1        NodeTyp    <," -1- ">
  17. Node2        NodeTyp    <," -2- ">
  18. Node3        NodeTyp    <," -3- ">
  19. Node4        NodeTyp    <," -4- ">
  20.  
  21. Data5        db    " -5- ",0
  22.  
  23. dseg        ends
  24.  
  25.  
  26.  
  27.  
  28. cseg        segment    para public 'code'
  29.         assume    cs:cseg, ds:dseg
  30.  
  31. ;
  32.         public    PSP
  33. PSP        dw    ?
  34.  
  35.  
  36. ; PrintDXSI- Prints the string pointed at by DX:SI.
  37.  
  38. PrintDXSI    proc
  39.         push    es
  40.         push    di
  41.         mov    es, dx
  42.         mov    di, si
  43.         puts
  44.         pop    di
  45.         pop    es
  46.         ret
  47. PrintDXSI    endp
  48.  
  49.  
  50. ; PrintList- Prints the list whose list variable is pointed at by ES:DI
  51.  
  52. PrintList    proc
  53.         push    es
  54.         push    di
  55.         push    dx
  56.         push    si
  57.  
  58.         les    di, es:[di].List.Head
  59. PrintLp:    mov    dx, es
  60.         cmp    dx, 0
  61.         jz    PrtDone
  62.         lea    si, [di+NodeSize]
  63.         call    PrintDXSI
  64.         les    di, es:[di].Node.Next
  65.         jmp    PrintLp
  66.  
  67. PrtDone:    putcr
  68.         pop    si
  69.         pop    dx
  70.         pop    di
  71.         pop    es
  72.         ret
  73. PrintList    endp
  74.  
  75.  
  76. ;
  77. ;
  78. ;
  79. Main        proc
  80.         mov    cs:PSP, es        ;Save pgm seg prefix
  81.         mov    ax, seg dseg        ;Set up the segment registers
  82.         mov    ds, ax
  83.         mov    es, ax
  84. ;
  85.         mov    dx, 0
  86.         meminit
  87.         jnc    GoodMemInit
  88.  
  89.         print
  90.         db    "Error initializing memory manager",cr,lf,0
  91.         jmp    Quit
  92. GoodMemInit:
  93.  
  94.  
  95. ;****************************************************************
  96. ;
  97. ; FIFO Queue routines test code
  98. ;
  99. ;****************************************************************
  100.  
  101.         print
  102.         db    "Testing the FIFO Queue Stuff: appendLast, appendlastm"
  103.         db    cr,lf,0
  104.  
  105.         lesi    MyList
  106.         ldxi    Node1
  107.         AppendLast
  108.         call    PrintList
  109.  
  110.         ldxi    Node2
  111.         lesi    MyList
  112.         AppendLast
  113.         call    PrintList
  114.  
  115.         ldxi    Node3
  116.         lesi    MyList
  117.         AppendLast
  118.         call    PrintList
  119.  
  120.         ldxi    Node4
  121.         lesi    MyList
  122.         AppendLast
  123.         call    PrintList
  124.  
  125.         ldxi    Data5
  126.         lesi    MyList
  127.         AppendLastm
  128.         call    PrintList
  129.  
  130.         print
  131.         db    cr,lf,lf
  132.         db    "Testing: Peek1st, Remove1st",cr,lf,lf,0
  133.  
  134. EmptyTheList:    lesi MyList
  135.         Peek1st
  136.         jc    EndOfFIFO
  137.         print
  138.         db    "Removing: ",0
  139.         mov    es, dx
  140.         lea    di, NodeSize[si]
  141.         puts
  142.         putcr
  143.  
  144.         lesi    MyList
  145.         call    PrintList
  146.         Remove1st
  147.         call    PrintList
  148.  
  149. ; If this node was allocated on the heap (Node5 above), free it here.
  150.  
  151.         mov    es, dx
  152.         mov    di, si
  153.         IsInHeap
  154.         jnc    NotInHeap
  155.         free
  156.  
  157. NotInHeap:    putcr
  158.         jmp    EmptyTheList
  159.  
  160. EndOfFIFO:    putcr
  161.  
  162.  
  163.  
  164. ;****************************************************************
  165. ;
  166. ; Deque routines test code
  167. ;
  168. ;****************************************************************
  169.  
  170.         print
  171.         db    cr,lf
  172.         db    "Testing the Deque routines:"
  173.         db    "Insert1st, Insert1stm, AppendLast",cr,lf
  174.         db    0
  175.  
  176.         lesi    MyList
  177.         ldxi    Node1
  178.         Insert1st
  179.         call    PrintList
  180.         putcr
  181.  
  182.         ldxi    Node2
  183.         Insert1st
  184.         call    PrintList
  185.         ldxi    Node2
  186.         AppendLast
  187.         call    PrintList
  188.         putcr
  189.  
  190.         ldxi    Node3
  191.         Insert1st
  192.         call    PrintList
  193.         ldxi    Node3
  194.         AppendLast
  195.         call    PrintList
  196.         putcr
  197.  
  198.         ldxi    Node4
  199.         Insert1st
  200.         call    PrintList
  201.         ldxi    Node4
  202.         AppendLast
  203.         call    PrintList
  204.         putcr
  205.  
  206.         ldxi    Data5
  207.         Insert1stm
  208.         call    PrintList
  209.  
  210.         print
  211.         db    cr,lf,lf
  212.         db    "Testing PeekLast, RemoveLast, Remove1st",cr,lf,0
  213.  
  214. EmptyTheList2:    lesi    MyList
  215.         PeekLast
  216.         jc    EndOfDeque
  217.         mov    es, dx
  218.         lea    di, NodeSize[si]
  219.         puts
  220.         print
  221.         db    "-- Removed: ",0
  222.  
  223.         lesi    MyList
  224.         RemoveLast
  225.  
  226. ; If this node was allocated on the heap (Node5 above), free it here.
  227.  
  228.         mov    es, dx
  229.         mov    di, si
  230.         IsInHeap
  231.         jnc    NotInHeap2
  232.         free
  233.  
  234. NotInHeap2:    lea    di, NodeSize[si]
  235.         puts
  236.         putcr
  237.  
  238.         cmp    word ptr  MyList.CurrentNode+2, 0
  239.         je    NoNext2
  240.  
  241.         print
  242.         db    "Next: ",0
  243.         les    di, MyList.CurrentNode
  244.         add    di, NodeSize
  245.         puts
  246.  
  247. NoNext2:    putcr
  248.         putcr
  249.         jmp    EmptyTheList2
  250.  
  251. EndOfDeque:
  252.  
  253.  
  254.  
  255. ;****************************************************************
  256. ;
  257. ; General List Manipulation Routines:
  258. ;
  259. ;****************************************************************
  260.  
  261.         print
  262.         db    cr,lf
  263.         db    "Testing the general list routines:",cr,lf
  264.         db    0
  265.  
  266. ; The list is currently empty, so inserting at the current node should
  267. ; put a new entry into the list.
  268.  
  269.         lesi    MyList
  270.         ldxi    Node1
  271.         InsertCur
  272.         print
  273.         db    "Node1: ",0
  274.         peekcur
  275.         mov    es, dx
  276.         lea    di, NodeSize[si]
  277.         puts
  278.         putcr
  279.  
  280.         lesi    MyList
  281.         ldxi    Node2
  282.         InsertCur
  283.         print
  284.         db    "Node2: ",0
  285.         peekcur
  286.         mov    es, dx
  287.         lea    di, NodeSize[si]
  288.         puts
  289.         putcr
  290.  
  291.         ldxi    Node3
  292.         lesi    MyList
  293.         InsertCur
  294.         print
  295.         db    "Node3: ",0
  296.         peekcur
  297.         mov    es, dx
  298.         lea    di, NodeSize[si]
  299.         puts
  300.         putcr
  301.  
  302.         ldxi    Node4
  303.         lesi    MyList
  304.         InsertCur
  305.         print
  306.         db    "Node4: ",0
  307.         peekcur
  308.         mov    es, dx
  309.         lea    di, NodeSize[si]
  310.         puts
  311.         putcr
  312.  
  313.         ldxi    Data5
  314.         lesi    MyList
  315.         InsertCurm
  316.         print
  317.         db    "Node5: ",0
  318.         peekcur
  319.         mov    es, dx
  320.         lea    di, NodeSize[si]
  321.         puts
  322.         putcr
  323.  
  324. EmptyTheList3:    lesi    MyList
  325.         RemoveCur
  326.         jc    EndofList
  327.  
  328. ; If this node was allocated on the heap (Node5 above), free it here.
  329.  
  330.         mov    es, dx
  331.         mov    di, si
  332.         IsInHeap
  333.         jnc    NotInHeap3
  334.         free
  335.  
  336. NotInHeap3:    print
  337.         db    "Removed: ",0
  338.         lea    di, NodeSize[si]
  339.         puts
  340.         putcr
  341.         jmp    EmptyTheList3
  342.  
  343. EndOfList:
  344.  
  345. Quit:        ExitPgm
  346. Main        endp
  347.  
  348. cseg            ends
  349.  
  350.  
  351.  
  352. ; Allocate a reasonable amount of space for the stack (2k).
  353.  
  354. sseg        segment    para stack 'stack'
  355. stk        db    256 dup ("stack   ")
  356. sseg        ends
  357.  
  358.  
  359. ; zzzzzzseg must be the last segment that gets loaded into memory!
  360.  
  361. zzzzzzseg    segment    para public 'zzzzzz'
  362. LastBytes    db    16 dup (?)
  363. zzzzzzseg    ends
  364.         end    Main
  365.